package com.yj.messageboard;

import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * Description:
 * Date: 2024-07-26
 * Time: 13:44
 */
@RestController
@RequestMapping("MessageBoard")
public class MessageController {
    private List<MessageInfo> list = new ArrayList<>();

    @RequestMapping("/getList")
    public List<MessageInfo> getList() {
        return list;
    }

    //发布留言，就是把留言信息加入 list
    @RequestMapping("/publish")
    public boolean publish(MessageInfo messageInfo) {
        //检查留言是否为空
        if(!StringUtils.hasLength(messageInfo.getDest())
                || !StringUtils.hasLength(messageInfo.getStart())
                || !StringUtils.hasLength(messageInfo.getMess()))
            return false;
        //不为空就加入 list
        list.add(messageInfo);
        return true;
    }

}
